package com.xyz.dao.dao;

import com.free.ext.mybatis.dao.BaseDao;
import com.free.ext.mybatis.model.entity.PageResponseModel;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.xyz.dao.mapper.SLotteryPeriodMapper;
import com.xyz.domain.model.LotteryPeriodSearchModel;
import com.xyz.domain.model.LotteryPeriodSearchResModel;
import com.xyz.domain.table.SLotteryPeriod;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import tk.mybatis.orderbyhelper.OrderByHelper;

import java.util.List;

@Repository
public class SLotteryPeriodDao extends BaseDao<SLotteryPeriod,Integer> {

    @Autowired
    private SLotteryPeriodMapper mapper;

    public Integer getLotteryMaxPeriod(SLotteryPeriod period){
        Integer res = mapper.getLotteryMaxPeriod(period);
        return  res == null ? 0 : res;
    }

    public List<LotteryPeriodSearchResModel> getLotteryPeriodList(LotteryPeriodSearchModel serCond){
        return mapper.getLotteryPeriodList(serCond);
    }

    public List<LotteryPeriodSearchResModel> getTodayLotteryInfo(LotteryPeriodSearchModel serCond){
        return mapper.getTodayLotteryInfo(serCond);
    }

    public PageResponseModel<LotteryPeriodSearchResModel> selectByPageNo(LotteryPeriodSearchModel condition, String orderBy, int pageNo, int pageSize) {
        Page<LotteryPeriodSearchResModel> lst = PageHelper.startPage(pageNo, pageSize);
        if (StringUtils.isNotEmpty(orderBy)) {
            OrderByHelper.orderBy(orderBy);
        }
        this.mapper.getLotteryPeriodList(condition);
        return new PageResponseModel(lst);
    }

    public PageResponseModel<LotteryPeriodSearchResModel> getTodayLotteryInfo(LotteryPeriodSearchModel condition, String orderBy, int pageNo, int pageSize){
        Page<LotteryPeriodSearchResModel> lst = PageHelper.startPage(pageNo, pageSize);
        if (StringUtils.isNotEmpty(orderBy)) {
            OrderByHelper.orderBy(orderBy);
        }
        getTodayLotteryInfo(condition);
        return new PageResponseModel(lst);
    }

    public List<SLotteryPeriod> getTop400Info(String lotteryCode){
        return mapper.get400PeriodInfo(lotteryCode);
    }

    public SLotteryPeriod getCurrentLotteryPeriodInfo(String lotteryCode){return mapper.getCurrentLotteryPeriodInfo(lotteryCode);}

}